package com.producer.广播队列;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class FanoutQueueController {
    @RequestMapping(value="/sendFanoutQueueMessage.do",method= RequestMethod.GET)
    @ResponseBody
    public String sendMessage(@RequestParam String message) {
        Map<String, String> msg = new HashMap<String, String>();
        msg.put("message", message);
        rabbitTemplate.convertAndSend(FanoutQueueConfig.FANOUT_EXCHANGE_NAME,
                FanoutQueueConfig.FANOUT_QUEUE_ROUTINGKEY, msg);
        return "消息发送成功";
    }
    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public FanoutQueueController(RabbitTemplate rabbitTemplate){
        this.rabbitTemplate = rabbitTemplate;
    }
}
